suyumen
目前主要在学习web相关

网鼎杯-2020-BabyJS

2021-08-06 ssrf js
Word count: 821 | Reading time: 3min

下载附件得到了一群代码,简单看了以下,完全做不来。。。真吓人。。

readme文件中有如下信息:

该目录下的文件,对应在远程主机上的目录为 /source ,
例如:该目录下 app.js 在远程主机上的绝对路径为 /source/app.js .

routes下的index.js文件里有:(但是没太明白为什么这个文件是主逻辑文件,在这个位置)

网上找到的wp不太多,只能勉强跟着做。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
var express = require('express');
var config = require('../config');
var url=require('url');
var child_process=require('child_process');
var fs=require('fs');
var request=require('request');
var router = express.Router();


var blacklist=['127.0.0.1.xip.io','::ffff:127.0.0.1','127.0.0.1','0','localhost','0.0.0.0','[::1]','::1'];

router.get('/', function(req, res, next) {
res.json({});
});

router.get('/debug', function(req, res, next) {
console.log(req.ip);
if(blacklist.indexOf(req.ip)!=-1){
console.log('res');
var u=req.query.url.replace(/[\"\']/ig,'');
console.log(url.parse(u).href);
let log=`echo '${url.parse(u).href}'>>/tmp/log`;
console.log(log);
child_process.exec(log);
res.json({data:fs.readFileSync('/tmp/log').toString()});
}else{
res.json({});
}
});


router.post('/debug', function(req, res, next) {
console.log(req.body);
if(req.body.url !== undefined) {
var u = req.body.url;
var urlObject=url.parse(u);
if(blacklist.indexOf(urlObject.hostname) == -1){
var dest=urlObject.href;
request(dest,(err,result,body)=>{
res.json(body);
})
}
else{
res.json([]);
}
}
});

module.exports = router;

console.log() : 控制台输出文本信息。

url.parse() : 将路径解析为一个方便操作的对象。

readFileSync() : 同步读取文件。

get请求上可以命令注入,但是当且仅当请求ip为本机时才可进入。

post请求上会进行二次请求,但是请求的url不能为本地ip。

思路:post请求中带url参数进行get请求。

本地回环地址

本地回环地址127.0.0.1指的是本机地址,不会跟着网络情况的变化而变化。它代表设备的本地虚拟接口,所以默认被看作是永远不会宕掉的接口。实际上:127.0.0.1 —> 127.255.255.254的范围都是本地回环地址

一般用来测试本机的网络配置:能ping127.0.0.1说明本机的IP协议安装没有问题。

或者代替localhost:windows中路径为C:\windows\system32\drivers\etc\hosts,Unix/Linux路径为/etc/hosts,将localhost127.0.0.1绑定在了一起。

此题中由于127.0.0.1127.255.255.254都是回环地址,所以可用127.0.0.2绕过。(127.1)

tail -F /dev/null

一般会利用tail -f /dev/null让容器一直处于runing状态,但是如果存在多个CMD指令,仅最后一个生效。

给两个wp也做不动。真没看明白,遂放弃。但还是学到了很多新东西。ssrf的题真难a。

参考

https://www.cnblogs.com/fyly/p/12827528.html

http://events.jianshu.io/p/8847cc103c66

https://blog.csdn.net/weixin_34146986/article/details/91516493?utm_term=web%E7%BD%91%E7%AB%99%E6%BA%90%E7%A0%81%E6%90%AD%E5%BB%BA%E6%95%99%E7%A8%8B&utm_medium=distribute.pc_aggpage_search_result.none-task-blog-2~all~sobaiduweb~default-1-91516493&spm=3001.4430

https://www.jianshu.com/p/117f12a72abd

https://blog.csdn.net/qq_45830543/article/details/113035212

https://blog.csdn.net/weixin_44555613/article/details/90897777

https://blog.csdn.net/u013452990/article/details/104535861

Author: suyumen

Link: https://suyumen.github.io/2021/08/06/2021-08-06-[%E7%BD%91%E9%BC%8E%E6%9D%AF2020]BabyJS/

Copyright: All articles in this blog are licensed under CC BY-NC-SA 3.0 unless stating additionally.

< PreviousPost
Docker环境搭建
NextPost >
尝试解决blog模板的滚动条bug
CATALOG
  1. 1. 本地回环地址
  2. 2. tail -F /dev/null
    1. 2.1. 参考